package com.persagy.demo;

import java.util.Random;

public class TestDataFactory {
	private static final String func_code_1 = "1101";
	private static final String func_code_2 = "1102";
	private static final String func_code_3 = "1103";
	private static final String func_code_4 = "1104";
	private static final String func_code_5 = "1105";
	
	/**
	 * 得到点位模拟数据，格式 meter;func,value;func,value#meter;func,value...
	 * 例：101;1101,67.05;1102,57.03;1103,11.27;1104,58.11;1105,42.47#102;1101,45.72;1102,13.20;1103,37.96;1104,70.36;1105,71.18
	 * @return
	 */
	public static String getData() {
		int meterNum = new Random().nextInt(20) + 1;
		
		StringBuilder sb = new StringBuilder();
		
		for(int i=0; i<meterNum; i++) {
			sb.append(getOrigData("#"+(101 + i)));
		}
		
		return sb.toString().substring(1);
	}
	
	private static String getOrigData(String meter) {
		return meter + ";" + func_code_1 + "," + getDoubleNum() +
				";" + func_code_2 + "," + getDoubleNum() +
				";" + func_code_3 + "," + getDoubleNum() +
				";" + func_code_4 + "," + getDoubleNum() +
				";" + func_code_5 + "," + getDoubleNum();
	}
	
	private static String getDoubleNum() {
		double d = 100 * Math.random();
		return String.format("%.2f", d);
	}
	
	public static void main(String[] args) {
		System.out.println(getData());
	}
}
